<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>预约安检列表</title>
</head>
<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">

<link rel="stylesheet" href="../../src/dist/css/page.css">

<body>
<div class="weui-cells user-recordList">
    <div class="weui-cells__tips">用户预约安检列表</div>
    <div class="weui-cells" id="listDemo">
        <img src="../../src/dist/img/nodata.png" alt="" class="nodataImg">
    </div>
    <div class="button_sp_area">
        <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="add()">预约+</a>
    </div>
</div>

<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<!-- Dist -->
<script src="../../src/dist/js/index.js"></script>
<script src="../../src/dist/js/utils.js"></script>
<script src="../../src/dist/js/request.js"></script>
<script>
    /*
    * 公众号获取数据基本流程：
    * 1.先请求接口获得一个URL
    * 2.跳转请求的URL，腾讯会重定向到本地的页面
    * 3.解析重定向的页面，获取code
    * 4.传递code，获取到openid
    * 5.openid是微信的唯一标识，拿到之后就可以请求自己的后台了（获取绑定用户下面的信息）
    * */
    var listData = [],
      wcode = '',
        customid = '';

    $(function(){
        var paras = location.search;            //search获得地址中的参数，内容为'?itemId=12'
        var result = paras.match(/[^\?&]*=[^&]*/g);     //match是字符串中符合的字段一个一个取出来，result中的值为['login=xx','table=admin']
        paras = {};                    //让paras变成没有内容的json对象
        for (i in result) {
            var temp = result[i].split('=');    //split()将一个字符串分解成一个数组,两次遍历result中的值分别为['itemId','xx']
            paras[temp[0]] = temp[1];
        }
        customid = paras.customid;     //根据参数名"itemId"，获取参数值

		getDataListPHP()
        //getDataList()
    })

    // 绑定新用户
    function add() {
       /* if(openid === ''){
            $.toast('未获取到openid，请重新进入页面!', 'forbidden');
            return
        }*/
        location.href  = './add.html?customid='+ customid
	}

	// 获取数据列表
    function getDataListPHP() {
        $.ajax({
            type: "POST",
            url: "../../src/php/requestOnline.php",
            data: {
                act: 'CSRQ_getDataListAppointent'
            },
            success: function (data) {
                data = eval('(' + data + ')')
                listData = data.list
                createListDemo()
            },
            error: function (data) {

            }
        });
	}
    function getDataList(){
        /*get("/wechat/binding/getList?openid="+ openid, {}, function (data) {
            if (data.code === 0) {
				listData = data.data
				createListDemo()
            } else {
                $.toast('获取数据失败!', 'forbidden');
            }
        }, false, true);*/
        $.ajax({
            type: "POST",
            url: CJINGdataLink+"/Controllers/CustomerServiceCenter/SecurityCheck/OfficialApplicationHandler.ashx",
            data: {
                cmd: " getdata",
                JsonData: JSON.stringify({})
            },
            success: function (data) {
                data = eval('(' + data + ')')

                if(!data.list || data.list.length ===0 ){
                    $.toast('暂无数据!', 'text');
                    return
                }
                listData = data
                createListDemo()
            },
            error: function (data) {
                $.toast('获取数据失败!', 'forbidden');
            }
        });
    }
    // 创建列表
    function createListDemo() {
      let d = listData
      let h = ''
      for(let [index, item] of d.entries()){
          h += '<div class="list-card" onclick="showDetail(\''+ item.ID +'\')">\n' +
      '            <div class="card-h">\n' +
      '                <i class="iconfont iconyonghuming"></i>\n' +
      '                <span class="card-key">用户名称：</span>\n' +
      '                <span class="card-value">'+item['PartyName']+'</span>\n' +
      '            </div>\n' +
      '            <div class="card-h">\n' +
      '                <i class="iconfont iconzhanghao"></i>\n' +
      '                <span class="card-key"> 用户号：</span>\n' +
      '                <span class="card-value">'+item['PartyCode']+'</span>\n' +
      '            </div>\n' +
      '            <div class="card-h">\n' +
      '                <i class="iconfont icondizhi"></i>\n' +
      '                <span class="card-key"> 用户地址：</span>\n' +
      '               <span class="card-value">'+(item['PartyAddress'])+'</span>\n' +
      '            </div>\n' +
      '            <div class="card-h">\n' +
      '                <i class="iconfont icondianhua"></i>\n' +
      '                <span class="card-key"> 用户电话：</span>\n' +
      '                <span class="card-value">'+ item['PartyPhone']+'</span>\n' +
      '            </div>\n' +
      '            <div class="card-h">\n' +
      '                <i class="iconfont iconleixing"></i>\n' +
      '                <span class="card-key"> 类型：</span>\n' +
      '                <span class="card-value">'+ (Number(item['Type']) == 0 ? "安检":"点火")+'</span>\n' +
      '            </div>\n' +
      '            <div class="card-h">\n' +
      '                <i class="iconfont iconshijian"></i>\n' +
      '                <span class="card-key"> 预约时间：</span>\n' +
      '                <span class="card-value">'+ item['ApplyDate']+'</span>\n' +
      '            </div>\n' +
      '        </div>'
      }
      $("#listDemo").html(h)
	}
    function showDetail(id) {
        location.href="./detail.html?id="+id
    }
	// 解除绑定
    function deleteUser(i) {
        $.actions({
            actions: [{
                text: "解除绑定",
                onClick: function () {
                    //do something
                    let customid = listData[i]['id']
                    get("/wechat/binding/delBinding?customid="+ customid + "&openid="+ openid, {}, function (data) {
                        if (data.code === 0) {
                            location = location
                        } else {
                            $.toast('解除绑定失败!', 'forbidden');
                        }
                    }, false, true);
                }
            }, {
                text: "查看缴费记录",
                onClick: function () {
                    //do something
                    let customid = listData[i]['id']
					location.href = './paymentRecords.html?openid=' + openid + '&customid='+ customid
                }
            }]
        });
	}
</script>
</body>
</html>
